{{extend name="layout/base-html"}}

{{block name="body"}}
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="name" class="layui-form-label"><span class="x-red">*</span>名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{{$data.name|default=''}}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>描述</label>
                <div class="layui-input-block">
                    <textarea name="description" placeholder="请输入描述"
                              class="layui-textarea">{{$data.description|default=''}}</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>

                <button class="layui-btn" lay-filter="{{$data ? 'edit' : 'add'}}" lay-submit="">
                    {{$data ? '修改' : '增加'}}
                </button>
            </div>
        </form>
    </div>
</div>

<script type="module">
    import {update, save} from "/static/admin/js/api/additional/ad-cate.js";

    layui.use(['form', 'layer', 'transfer'], () => {
        let $ = layui.jquery,
            form = layui.form;

        let event = '{{$data ? "edit" : "add"}}';

        // 监听事件
        formData(form, event, 'edit' === event ? {
            request: update,
            id: '{{$data.id|default=0}}',
        } : {
            request: save,
        });
    });
</script>
{{/block}}
